package com.ez.supervise.action.biz;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.apache.commons.lang.math.NumberUtils;

import com.ez.supervise.action.base.BaseJsonAction;
import com.ez.supervise.core.Page;
import com.ez.supervise.model.biz.OrgCheck;
import com.ez.supervise.service.QueryService;
import com.ez.supervise.util.JsonUtils;

public class QueryAction extends BaseJsonAction {

    private static final long serialVersionUID = 585976345704483184L;
    private Long id;
    private QueryService queryService;
    private OrgCheck orgCheck;
    private Page page;

    public String queryCheckProgressByPage() {
	try {
	    page = new Page();
	    page.putCondition("year", NumberUtils.isNumber(getRequest().getParameter("year")) ? Long.valueOf(getRequest().getParameter("year")) : null);
	    page.putCondition("categoryId", NumberUtils.isNumber(getRequest().getParameter("categoryId")) ? Long.valueOf(getRequest().getParameter("categoryId")) : null);
	    page.putCondition("orgId", NumberUtils.isNumber(getRequest().getParameter("orgId")) ? Long.valueOf(getRequest().getParameter("orgId")) : null);
	    page.putCondition("goStatus",getRequest().getParameter("goStatus"));
	    page.putCondition("content",getRequest().getParameter("content"));
	    int start = NumberUtils.toInt(getRequest().getParameter("start"), 0);
	    int limit = NumberUtils.toInt(getRequest().getParameter("limit"), 20);
	    page.setStart(start++);
	    page.setLimit(limit);
	    page.addPageInfo();
	    queryService.queryCheckProgressByPage(page);
	    outJsonString(JsonUtils.fromObject(page, new String[] { "creator", "createTime", ",modifier", "modifyTime",
		"isDeleted", "new" }));
	    
	} catch (Exception e) {
	    e.printStackTrace();
	    outString(RESULT_FAIL);
	}
	return SUCCESS;
    }
    
    public String queryCheckResultByPage() {
	try {
	    page = new Page();
	    page.putCondition("year", NumberUtils.isNumber(getRequest().getParameter("year")) ? Long.valueOf(getRequest().getParameter("year")) : null);
	    page.putCondition("categoryId", NumberUtils.isNumber(getRequest().getParameter("categoryId")) ? Long.valueOf(getRequest().getParameter("categoryId")) : null);
	    page.putCondition("orgId", NumberUtils.isNumber(getRequest().getParameter("orgId")) ? Long.valueOf(getRequest().getParameter("orgId")) : null);
	    page.putCondition("goStatus",getRequest().getParameter("goStatus"));
	    page.putCondition("content",getRequest().getParameter("content"));
	   
	    int start = NumberUtils.toInt(getRequest().getParameter("start"), 0);
	    int limit = NumberUtils.toInt(getRequest().getParameter("limit"), 20);
	    page.setStart(start++);
	    page.setLimit(limit);
	    page.addPageInfo();
	    queryService.queryCheckResultByPage(page);
	    outJsonString(JsonUtils.fromObject(page, new String[] { "creator", "createTime", ",modifier", "modifyTime",
		"isDeleted", "new" }));
	    
	} catch (Exception e) {
	    e.printStackTrace();
	    outString(RESULT_FAIL);
	}
	return SUCCESS;
    }
    
     
    public String findOrgCheckByPage(){
	try {
	    page = new Page();
	    page.putCondition("year", NumberUtils.isNumber(getRequest().getParameter("year")) ? Long.valueOf(getRequest().getParameter("year")) : null);
	    page.putCondition("orgId", NumberUtils.isNumber(getRequest().getParameter("orgId")) ? Long.valueOf(getRequest().getParameter("orgId")) : null);
	    int start = NumberUtils.toInt(getRequest().getParameter("start"), 0);
	    int limit = NumberUtils.toInt(getRequest().getParameter("limit"), 20);
	    page.setStart(start++);
	    page.setLimit(limit);
	    page.addPageInfo();
	    queryService.queryCheckProgressByPage(page);
	    outJsonString(JsonUtils.fromObject(page, new String[] { "creator", "createTime", ",modifier", "modifyTime",
		"isDeleted", "new" }));
	    
	} catch (Exception e) {
	    e.printStackTrace();
	    outString(RESULT_FAIL);
	}
	return SUCCESS;
    }

    public Long getId() {
	return id;
    }

    public void setId(Long id) {
	this.id = id;
    }

    public static void main(String[] args) {
	OrgCheck orgCheck = new OrgCheck();
	orgCheck.setId(1L);
	// orgCheck.setName("linlinyu");
	JSONObject json = JSONObject.fromObject(orgCheck);

	System.out.println(json);

	JsonConfig config = new JsonConfig();
	config.setExcludes(new String[] { "creator", "createTime", ",modifier", "modifyTime", "isDeleted", "new", });

	JSONObject jsonObj = JSONObject.fromObject(orgCheck, config);
	System.out.println(jsonObj.toString());
    }

    public void setQueryService(QueryService queryService) {
	this.queryService = queryService;
    }

    public OrgCheck getOrgCheck() {
	return orgCheck;
    }

    public void setOrgCheck(OrgCheck orgCheck) {
	this.orgCheck = orgCheck;
    }

    public Page getPage() {
	return page;
    }

    public void setPage(Page page) {
	this.page = page;
    }

}
